package solution._0210._0215;

import java.util.AbstractQueue;
import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created by chen_snow
 * Date: 2021/7/14 23:25
 * Description:
 */
public class Solution {
    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue(k, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for (int i = 0; i < nums.length; i++) {
            queue.offer(nums[i]);
        }

        for (int i = 0; i < k-1; i++) {
            queue.poll();
        }
        return queue.poll();
    }
}
